import os
import cv2
import numpy as np

path = './data/all_data/Bago_highway_1'
filelist = os.listdir(path)
filelist.sort()
fps = 16 #视频每秒24帧
size = (640, 480) #需要转为视频的图片的尺寸
#可以使用cv2.resize()进行修改

video = cv2.VideoWriter("VideoTest1.avi", cv2.VideoWriter_fourcc('I', '4', '2', '0'), fps, size)
#视频保存在当前目录下

for item in filelist:
    if item.endswith('.jpg'):
        print(item)
        item = path +'/'+ item
        img = cv2.imread(item)
        img = cv2.resize(img, size)

        video.write(img)

video.release()
cv2.destroyAllWindows()
print('end')